package models

import (
	"driver_srv/basic/config"
	"time"
)

// 司机培训课程
type DriverTrainingCourse struct {
	Id         uint32    `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	DriverId   uint32    `gorm:"column:driver_id;type:int UNSIGNED;comment:司机ID;not null;" json:"driver_id"`       // 司机ID
	CourseName string    `gorm:"column:course_name;type:varchar(100);comment:培训课程名称;not null;" json:"course_name"` // 培训课程名称
	CourseDate time.Time `gorm:"column:course_date;type:date;comment:培训课程日期;not null;" json:"course_date"`         // 培训课程日期
	StartDate  time.Time `gorm:"column:start_date;type:datetime;comment:培训开始日期;not null;" json:"start_date"`       // 培训开始日期
	EndDate    time.Time `gorm:"column:end_date;type:datetime;comment:培训结束日期;not null;" json:"end_date"`           // 培训结束日期
	Duration   uint32    `gorm:"column:duration;type:int UNSIGNED;comment:培训时长;not null;" json:"duration"`         // 培训时长
	CreatedAt  time.Time `gorm:"column:created_at;type:datetime;not null;default:CURRENT_TIMESTAMP;" json:"created_at"`
	UpdatedAt  time.Time `gorm:"column:updated_at;type:datetime;not null;default:CURRENT_TIMESTAMP;" json:"updated_at"`
}

func (d *DriverTrainingCourse) TableName() string {
	return "driver_training_course"
}
func (d *DriverTrainingCourse) DriverTrainingCourseCreate() error {
	return config.DB.Create(&d).Error
}

// 根据司机ID获取培训课程列表
func (d *DriverTrainingCourse) FindTrainingCoursesByDriverId() ([]DriverTrainingCourse, error) {
	var courses []DriverTrainingCourse
	err := config.DB.Where("driver_id = ?", d.DriverId).Find(&courses).Error
	return courses, err
}
